<template>
	<view class="container">
		<view class="uni-list">
			<case-list-content :list-data="listData" :rows="rows">
				<template #btns="item">
					<button v-if="item.data.conserveStatus=='1'&& item.data.conserveSchedule !='100'" class="common-btn primary-btn"  size="mini" @click="handleDeal(item.data)">养护填报</button>
				</template>
			</case-list-content>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data";
	import { dateUtils } from  '@/utils/util.js';
	import {
	  listPubConservePlan,
	  getPubConservePlan,
	  delPubConservePlan,
	  addPubConservePlan,
	  updatePubConservePlan,
	} from "@/api/pub/pubConservePlan.js";
	export default {
		data(){
			return {
				queryParams:{
					caseCode:"",
					reportTime:[]
				},
				page:1,
				size:10,
				total:0,
				listData: [],
				rows:[{
					labelName:"计划名称",
					valueName:"name"
				},{
					labelName:"养护范围",
					valueName:"conserveRange"
				},{
					labelName:"开始时间",
					valueName:"conserveStartTime"
				},{
					labelName:"结束时间",
					valueName:"conserveEndTime"
				}],
				reload: false,
				status: 'noMore',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				sourceOptions:[]
			}
		},
		methods:{
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				this.queryParams.conserveObjType = "2";
				listPubConservePlan(this.queryParams).then(res => {
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;
						list.forEach(item => {
							if(item.rptChannelId){
								this.sourceOptions.forEach(opt => {
									if(opt.dictValue == item.rptChannelId){
										item.caseSource = opt.dictLabel;
									}
								})
							}
						})
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
					}
				})
			},
			handleQuery(){
				if(this.queryParams.reportTime &&　this.queryParams.reportTime.length>0){
					let params = {
						"rptTimeStrStart":this.queryParams.reportTime[0]+" 00:00:00",
						"rptTimeStrEnd":this.queryParams.reportTime[1]+" 23:59:59"
					}
					this.queryParams.params = params;
				}
				this.page = 1;
				this.reload = true;
				this.listData = [];
				this.getList();
			},
			handleRepeat(){
				this.queryParams = {};
			},
			handleDeal(item){
				item.conserveRangePoint = null;
				console.log(JSON.stringify(item));
				uni.navigateTo({
					url:'/pages/waterSupply/yanghu/xcinfo/xcinfo?rowData='+JSON.stringify(item)
				})
			}
		},
		
		onLoad() {
			//问题来源
			getDicts("case_source").then(response => {
				this.sourceOptions = response.data;
			});
		},
		onShow() {
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onNavigationBarButtonTap : function (e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh(){
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			this.getList();
		}
	}
</script>

<style lang="scss">
	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}
	.nav-btn{
		margin-right: 15px;
	}
</style>